from django.db import transaction
from django.db.models.signals import post_save
from django.dispatch import receiver

from social.notification.models import Notification
from social.notification.tasks import send_post_notification


@receiver(post_save, sender=Notification)
def post_post_save(sender, instance: Notification, created, **kwargs):
    if created:
        transaction.on_commit(lambda: send_post_notification.delay(instance.id))
